﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace TPAMainReportTools
{
    public class UserInfo
    {
        SqlTools sqt;

        string strSelectUserInfo = "select yh001 用户名称 from yh_table where yh001='@用户名称' and yh005='@密码'";

        private string _UserName;
        private bool _LoginSuccess;
        private string _LoginErrMsg;

        /// <summary>
        /// 获取用户名称
        /// </summary>
        public string UserName
        {
            get
            {
                return _UserName;
            }
        }

        /// <summary>
        /// 获取用户登录是否成功
        /// </summary>
        public bool LoginSuccess
        {
            get
            {
                return _LoginSuccess;
            }
        }

        /// <summary>
        /// 获取用户登录错误信息
        /// </summary>
        public string LoginErrMsg
        {
            get
            {
                return _LoginErrMsg;
            }
        }

        public UserInfo(string strTmpUserName, string strTmpPassword)
        {
            _UserName = strTmpUserName;
            //sqt = new SqlTools(GeneralTools.GetConnectionString("192.168.1.1", "TPAMain"));
            sqt = new SqlTools(GeneralTools.GetConnectionString("TPAMain"));
            DataTable tmpdt = sqt.GetData(strSelectUserInfo.Replace("@用户名称", strTmpUserName)
                                                                                      .Replace("@密码", strTmpPassword));
            if (tmpdt.Rows.Count == 0)
            {
                _LoginSuccess = false;
                _LoginErrMsg = "用户不存在或密码不正确！";
            }
            else
            {
                if (strTmpPassword.Equals(string.Empty))
                {
                    _LoginSuccess = false;
                    _LoginErrMsg = "密码不能为空，空密码的用户不允许登录！";
                }
                else
                {
                    _LoginSuccess = true;
                    _LoginErrMsg = string.Empty;
                }
            }
        }
    }
}